package com.lcj.ai.config;

import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * <p>
 *
 * </p>
 *
 * @author: liuchangjun
 * @since: 2023/12/22 14:59
 */

@Configuration
@RequiredArgsConstructor
@EnableAsync
public class WebConfig implements WebMvcConfigurer {

    private final TraceIdInterceptor traceIdInterceptor;

    /**
     * oss文件存储路径,保存生成的语音文件和图片文件
     */
    @Value("${spring.cloud.ai.oss.path}")
    private String ossPath;


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(traceIdInterceptor).order(0);
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/oss/**")
                .addResourceLocations("file:" + ossPath);
    }
}
